<template>
  <div class="searchContainer">
    <el-checkbox-group v-model="selectedId" :class="{ optionsBox: true, isExtend: isExtend }"
      @change="handleCheckboxChange" :max="limitNum == 1 ? 99 : limitNum">
      <el-checkbox :label="item.dataValue + '-' + item.dataName" v-for="(item, index) in list"
        :key="index">{{ item.dataName }}</el-checkbox>
    </el-checkbox-group>
    <!-- <div class="switchBtn" @click="handleSwitchBtnClick">
      <span v-if="!isExtend">更多<i class="el-icon-arrow-down"></i></span>
      <span v-else>收起<i class="el-icon-arrow-up"></i></span>
    </div> -->
  </div>
</template>

<script>
export default {
  name: "targetCheckbox",
  props: {
    limitNum: {
      type: Number,
      default: 5,
    },
    disableDefault: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      list: [],
      selectedId: [],
      isExtend: false,
    };
  },
  created() {
    this.fetchData();
  },
  deactivated() {
    this.selectedId = [];
  },
  beforeDestroy() {
    this.selectedId = [];
  },
  methods: {
    fetchData() {
      this.list = [
        {
          dataName: "全部",
          dataValue: "",
        },
        {
          dataName: "应届生",
          dataValue: "1",
        },
        {
          dataName: "社会人士",
          dataValue: "0",
        },
      ];
      if (this.disableDefault) return;
      this.selectedId = [this.list[0].dataValue + "-" + this.list[0].dataName];
      this.$emit("onTargetChange", [
        this.list[0].dataValue + "-" + this.list[0].dataName,
      ]);
    },
    handleCloseClick(item) {},
    handleCheckboxChange(item) {
      if (this.limitNum == 1) {
        this.selectedId = [];
        if (item && item.length) {
          this.selectedId.push(item[item.length - 1]);
        }
      }
      this.$emit("onTargetChange", this.selectedId);
    },
    handleSwitchBtnClick() {
      this.isExtend = !this.isExtend;
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-checkbox {
  font-weight: 400;
  .el-checkbox__inner {
    width: 12px;
    height: 12px;
    border-radius: 3px;
  }
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #fff;
  }
  .el-checkbox__input.is-focus .el-checkbox__inner {
    background-color: #fff;
    border-color: #dcdfe6;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner {
    background-color: #fff;
    border-color: #409eff;
  }
  .el-checkbox__inner::after {
    left: 3px;
    height: 5px;
    width: 3px;
    border: 1px solid #409eff;
    border-left: 0;
    border-top: 0;
  }
  .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
    left: 3px;
    height: 5px;
    width: 3px;
    border: 1px solid #409eff;
    border-left: 0;
    border-top: 0;
    border-color: #409eff;
  }
}
// ::v-deep .el-checkbox__label {
//   font-size: 14px;
//   font-family: PingFangSC-Regular, PingFang SC;
//   font-weight: 400;
//   color: #555555;
//   line-height: 20px;
// }
::v-deep .el-checkbox__input.is-checked + .el-checkbox__label {
  color: #409eff;
}
// ::v-deep .el-checkbox__input.is-checked + .el-checkbox__inner {
//   color: #1b78ff;
// }
.searchContainer {
  display: flex;
  align-items: flex-start;
  max-width: 100vw;
  .optionsBox {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    // width: 1000px;
    height: 40px;
    overflow: hidden;
    transition: height 0.2s;
    .optionItem {
      display: flex;
      align-items: center;
      color: #333;
      float: left;
      line-height: 1.2;
      padding: 5px 10px;
      border-radius: 4px;
      cursor: pointer;
      margin-right: 5px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      &:hover {
        background-color: #e4e4e4;
      }
    }
    .selected {
      background-color: #e4e4e4;
    }
    &.isExtend {
      height: auto;
      transition: height 0.2s;
    }
    @keyframes extend {
      from {
        height: 26px;
      }
      to {
        height: 106px;
      }
    }
  }
  .switchBtn {
    color: #999;
    cursor: pointer;
    line-height: 1.2;
    padding: 5px 10px;
    border-radius: 4px;
    margin-right: 60px;
    white-space: nowrap;
    // overflow: hidden;
    // text-overflow: ellipsis;
    margin-top: 8px;

    background: #f1f1f1;
  }
}
.close {
  margin-left: 4px;
}
</style>
